# !/bin/bash

# 获取处理数据日期值，如果传递直接赋值，否则获取前一天日期
if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi


# 将MySQL数据库中地理区域字段表数据同步到HDFS
/opt/module/sqoop/bin/sqoop import \
--connect jdbc:mysql://node101:3306/jtp_gmall_shucang \
--username root \
--password 123456 \
--as-textfile \
--query 'SELECT log_id, user_id, session_id, page_id, page_type, module_id, module_type, click_time, stay_duration, refer_page, device_type, os, province, city, ip, extra_info
         FROM  jtp_gmall_shucang.ods_page_log WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir  'hdfs://node101:8020/user/spark/warehouse/jtp_page_shucang/ods_page_log/${data_date}' \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'



/opt/module/sqoop/bin/sqoop import \
--connect jdbc:mysql://node101:3306/jtp_gmall_shucang \
--username root \
--password 123456 \
--as-textfile \
--query 'SELECT order_id, user_id, shop_id, product_id, content_id, order_time, pay_time, pay_amount, pay_method, order_status, province, city, is_first_order, coupon_amount, shipping_fee, create_time, dt
         FROM jtp_gmall_shucang.ods_orders WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir  'hdfs://node101:8020/user/spark/warehouse/jtp_page_shucang/ods_orders/${data_date}' \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'
